package com.gancp.controller;

import com.gancp.common.Constans;
import com.gancp.controller.BaseController.BaseController;
import com.gancp.domain.MessageBord;
import com.gancp.service.MessageBordBiz;
import com.gancp.utills.PageHelperUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * Created by GCP on 2018/4/27.
 * 主页
 */
@Controller
@RequestMapping("home")
public class HomePageController extends BaseController {
    @Autowired
    private MessageBordBiz messageBordBiz;

    @RequestMapping("")
    public String gotoHomePage() {
        return "home";
    }

    @RequestMapping("/saveMessage")
    public @ResponseBody
    String saveMessageBord(HttpServletRequest request) {
        MessageBord record = new MessageBord();
        String content = request.getParameter( "content" );
        String mood = request.getParameter( "mood" );
        record.setUserid( getUserId( request ) );
        record.setContent( content );
        record.setMood( mood );
        record.setCreatdate( new Date() );
        record.setCity( "南昌" );
        messageBordBiz.insertSelective( record );
        return "success";
    }


    /**
     * @Author gancp
     * @Date 时间被黑洞吸走了
     * @Descripition 加载留言板消息
     **/
    @RequestMapping("/queryMessageBordList")
    public @ResponseBody
    PageInfo<MessageBord> queryMessageBordList(HttpServletRequest request) {
        PageHelperUtils.execute( request );
        List<MessageBord> list = messageBordBiz.selectMsgBordListByParam( new MessageBord() );
        PageInfo<MessageBord> pageInfo = new PageInfo<MessageBord>( list );
        return pageInfo;
    }
}
